classdef SkillDistribution < handle

    properties
        mass % used for normalization in case of truncation,
             % default is 1
        
        aM
        muM
        sigmaM
        shareM
        
        aR
        muR
        sigmaR
        shareR        
        
        aC
        muC
        sigmaC
        shareC               
        
    end

    methods

        
        function self = SkillDistribution(par, varargin)
            p = inputParser;
            p.KeepUnmatched = true;

            addParameter(p, 'mass', 1, @(x) x > 0);
            parse(p, varargin{:});
            self.mass = p.Results.mass;

            self.aM = par.aM;
            self.muM = par.muM;
            self.sigmaM = par.sigmaM;
            self.shareM = par.shareM;
            
            self.aR = par.aR;
            self.muR = par.muR;
            self.sigmaR = par.sigmaR;
            self.shareR = par.shareR;            
            
            self.aC = par.aC;
            self.muC = par.muC;
            self.sigmaC = par.sigmaC;
            self.shareC = par.shareC;                
        end


        function out = f(self, w, Y_M, Y_R, Y_C)
            out = self.f_M(w, Y_M, Y_R, Y_C) + ...
                  self.f_R(w, Y_M, Y_R, Y_C) + ...
                  self.f_C( w, Y_M, Y_R, Y_C);
        end        
        
        
        function out = f_M(self, w, Y_M, Y_R, Y_C)
            aM = self.aM;
            muM = self.muM;
            sigmaM = self.sigmaM;
            shareM = self.shareM;
            
            out = shareM .* 1/Y_M.*plognpdf(w./Y_M, aM, muM, sigmaM)./self.mass;
        end        

        
        function out = f_R(self, w, Y_M, Y_R, Y_C)
            aR = self.aR;
            muR = self.muR;
            sigmaR = self.sigmaR;
            shareR = self.shareR;
            
            out = shareR .* 1/Y_R.*plognpdf(w./Y_R, aR, muR, sigmaR)./self.mass;
        end        

        
        function out = f_C(self, w, Y_M, Y_R, Y_C)
            aC = self.aC;
            muC = self.muC;
            sigmaC = self.sigmaC;
            shareC = self.shareC;
            
            out = shareC .* 1/Y_C.*plognpdf(w./Y_C, aC, muC, sigmaC)./self.mass;
        end        

        
    end
end